﻿using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using VSLangProj;
using System.Collections.Specialized;
using System.Text;
using Sharp.UnusedReferences.Options;
using System.Windows.Media.Animation;
using Sharp.UnusedReferences.Helpers;
using System.ComponentModel.Design;

namespace Sharp.UnusedReferences
{
	/// <summary>
	/// Interaction logic for MyControl.xaml
	/// </summary>
	public partial class UserControlSolutionTree : UserControl
	{
		#region Constructors
		
		public UserControlSolutionTree()
		{
			DebugHelper.LogCall();
			InitializeComponent();
		}

#endregion

		#region Fields
		Hashtable HashtableProjectUsedReferencedAssemblis;
		public event EventHandler ItemCheckedChanged;
		const string stringReportFolder = "Sharp.UnusedReferences.Report.";
		const string stringImagePath = "Images";
		private StringBuilder StringBuilderNodesXml;
		private const string stringProjectMarkup = @"
							<!--Project-->
							<tr>
								<td class=""SectionTitle"" colspan=""2"">
									Project: {0}<!--Project name-->
								</td>
							</tr>
							<tr>
								<td class=""TableHeader"">
									Filename
								</td>
								<td class=""TableHeader"">
									Number of unused references
								</td>
							</tr>
							<tr class=""row"">
								<td class=""content"">
									<img onload=""MaintainVisibilityBasedOnNumberOfUnusedReferences(event);"" onclick=""outliner(event);"" style=""cursor: pointer;"" width=""9"" height=""11"" class=""expandable"" alt=""expand/collapse section"" src=""Images/GridPlus.gif"" border=""0"" />
									{1}<!--Project file path-->
								</td>
								<td class=""content"">
									{2}<!--Number of unused references in the project-->
								</td>
							</tr>
							<tr style=""display:none;"" bgcolor=""#ffffff"">
								<td colspan=""2"" style=""padding-left: 17px;"">
									<table class=""issuetable"" border=""1"" rules=""cols"" bordercolor=""#dcdcdc"" width=""100%"">
										<tr>
											<td class=""issuetitle"">
												Reference
											</td>
											<td class=""issuetitle"">
												Type
											</td>
											<td class=""issuetitle"">
												Is Project
											</td>
											<td class=""issuetitle"">
												Path
											</td>
										</tr>
{3}<!--References markup-->
									</table>
								</td>
							</tr>
							<tr>
								<td class=""foot"" colspan=""2"">
									&nbsp;
								</td>
							</tr>
";
		private const string stringReferenceMarkup = @"
										<tr>
											<td style=""border-bottom: lightgray 1px solid"" class=""issuenone"">
												{0}<!--Reference name-->
											</td>
											<td style=""border-bottom: lightgray 1px solid"" class=""issuenone"">
												{1}<!--Reference type (project, COM or .net)-->
											</td>
											<td style=""border-bottom: lightgray 1px solid"" class=""issuenoneCenter"">
												{2}<!--Is project Reference (project)-->
											</td>
											<td style=""border-bottom: lightgray 1px solid"" class=""issuenone"">
												{3}<!--Reference path-->
											</td>
										</tr>
";
		private const string stringSettingsMarkup = @"
							<tr>
								<td colspan=""2"" style=""font-weight: bold; font-size: 13"">
									{0} settings:
								</td>
							</tr>
							{1}
							<td>
								<br />
							</td>
";
		private const string stringSettingMarkup = @"
							<tr>
								<td nowrap=""nowrap"" style=""font-weight: bold"">
									{0}:
								</td>
								<td style=""width: 100%"">
									{1}
								</td>
							</tr>
";
		private int intNumberOfUnusedReferencesInSolution = 0;
		private Dictionary<uint, string> DictionaryCheckedIds;

		#endregion

		#region Public Functions

		internal void ClearNodes()
		{
			DebugHelper.LogCall();
			TreeViewSolutionHierarchy.Items.Clear();
			NumberOfCheckedReferences = 0;
		}
		internal void RefreshNodes(Hashtable HashtableProjectUsedReferencedAssemblis)
		{
			DebugHelper.LogCall();
			ClearNodes();
			this.HashtableProjectUsedReferencedAssemblis = HashtableProjectUsedReferencedAssemblis;
			IVsSolution solution = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolution)) as IVsSolution;
			IVsHierarchy IVHSolution = (IVsHierarchy)solution;
			IVsHierarchyWrapper IVHWSol = new IVsHierarchyWrapper(IVHSolution, VSConstants.VSITEMID_ROOT);
			CheckBoxTreeViewItem TreeNodeSolution = CreateCheckBoxTreeViewItem(IVHWSol);
			TreeViewSolutionHierarchy.Items.Add(TreeNodeSolution);
			GetHChildren(TreeNodeSolution, IVHWSol);
			((CheckBoxTreeViewItem)TreeViewSolutionHierarchy.Items[0]).IsExpanded = true;
			//DTE2 dte = ServiceProvider.GlobalProvider.GetService(typeof(SDTE)) as DTE2;
			//dte.ToolWindows.SolutionExplorer.UIHierarchyItems aa;

			//Projects prs = dte.Solution.Projects;
			//clew.Insert(0, dte2.ToolWindows.SolutionExplorer.UIHierarchyItems.Item(1).Name);
		}
		internal void RemoveSelectedReferences()
		{
			DebugHelper.LogCall();
			if(TreeViewSolutionHierarchy.Items.Count > 0)
			{
				CheckBoxTreeViewItem CheckBoxTreeViewItemSolution = (CheckBoxTreeViewItem)TreeViewSolutionHierarchy.Items[0];
				if(CheckBoxTreeViewItemSolution.IsChecked != false)
				{
					foreach(CheckBoxTreeViewItem CheckBoxTreeViewItemProject in CheckBoxTreeViewItemSolution.Items)
					{
						if(CheckBoxTreeViewItemProject.Items.Count > 0)
						{
							CheckBoxTreeViewItem CheckBoxTreeViewItemReferences = (CheckBoxTreeViewItem)CheckBoxTreeViewItemProject.Items[0];
							if(CheckBoxTreeViewItemReferences.IsChecked != false)
							{
								IVsHierarchyWrapper IVsHierarchyWrapperProject = ((IVsHierarchyWrapper)CheckBoxTreeViewItemProject.Tag);
								CheckBoxTreeViewItem CheckBoxTreeViewItemReference;
								for(int intIndex = 0; intIndex < CheckBoxTreeViewItemReferences.Items.Count; intIndex++)
								{
									CheckBoxTreeViewItemReference = (CheckBoxTreeViewItem)CheckBoxTreeViewItemReferences.Items[intIndex];
									if(CheckBoxTreeViewItemReference.IsChecked == true)
									{
										IVsHierarchyWrapper IVsHierarchyWrapperReference = ((IVsHierarchyWrapper)CheckBoxTreeViewItemReference.Tag);
										IVsHierarchyWrapperReference.Remove();
										CheckBoxTreeViewItemReferences.Items.RemoveAt(intIndex);
										intIndex--;
									}
								}
							}
						}
					}
				}
			}
			NumberOfCheckedReferences = 0;
		}
		internal string ReportUnusedReferences(string OutputPath, string Title, Hashtable HashtableScanningSettingsForDisplay)
		{
			DebugHelper.LogCall();
			
			intNumberOfUnusedReferencesInSolution = 0;
			string stringDefaultFileResourceName = ExportHtmlContent(OutputPath, Title);
			if(StringBuilderNodesXml == null)
			{
				StringBuilderNodesXml = new StringBuilder();
			}
			else
			{
				StringBuilderNodesXml.Clear();
			}
			GetNodesXML(System.IO.Path.Combine(OutputPath, Title));
			string stringDefaultFilePath = GetSuitableOutputPath(stringDefaultFileResourceName, System.IO.Path.Combine(OutputPath, Title));
			string stringProjectsMarkup = GetProjectsMarkup();
			ExportResource(stringDefaultFileResourceName, stringDefaultFilePath, PackageUnusedReferences.ProductName, Title, Options.ToDateString(DateTime.Now), "Some description", Convert.ToInt16(Options.IncludeSelectionInExportedFile), StringBuilderNodesXml.ToString(), Assembly.GetExecutingAssembly().GetName().Version, intNumberOfUnusedReferencesInSolution, ((IVsHierarchyWrapper)((CheckBoxTreeViewItem)TreeViewSolutionHierarchy.Items[0]).Tag).FilePath, stringProjectsMarkup, GetSettingsMarkup(HashtableScanningSettingsForDisplay), Options.ToTimeString(DateTime.Now));
			return stringDefaultFilePath;
		}
		internal void SaveSelection()
		{
			DebugHelper.LogCall();
			if(DictionaryCheckedIds == null)
			{
				DictionaryCheckedIds = new Dictionary<uint,string>();
			}
			else
			{
				DictionaryCheckedIds.Clear();
			}
			foreach(CheckBoxTreeViewItem CheckBoxTreeViewItemProject in ((CheckBoxTreeViewItem)TreeViewSolutionHierarchy.Items[0]).Items)
			{
				foreach(CheckBoxTreeViewItem itm in CheckBoxTreeViewItemProject.ChildItems[0].ChildItems)
				{
					if(itm.IsChecked.Value)
					{
						DictionaryCheckedIds.Add(itm.GetIVsHierarchyWrapper().ItemId, itm.GetIVsHierarchyWrapper().LogicalPath);
					}
				}
			}
		}
		internal void LoadSelection(bool ShowInformationAboutDifference)
		{
			DebugHelper.LogCall();
			if(DictionaryCheckedIds == null || DictionaryCheckedIds.Count == 0)
			{
				return;
			}
			foreach(CheckBoxTreeViewItem CheckBoxTreeViewItemProject in ((CheckBoxTreeViewItem)TreeViewSolutionHierarchy.Items[0]).Items)
			{
				foreach(CheckBoxTreeViewItem itm in CheckBoxTreeViewItemProject.ChildItems[0].ChildItems)
				{
					uint ItemId = itm.GetIVsHierarchyWrapper().ItemId;
					if(DictionaryCheckedIds.ContainsKey(ItemId))
					{
						itm.IsChecked = true;
						DictionaryCheckedIds.Remove(ItemId);
					}
				}
			}
			if(ShowInformationAboutDifference && DictionaryCheckedIds.Count > 0)
			{
				StringBuilder StringBuilderGhostReferences = new StringBuilder("The following references become used since last scan:\n");
				foreach(uint ItemId in DictionaryCheckedIds.Keys)
				{
					StringBuilderGhostReferences.AppendFormat("\t{0}\n", DictionaryCheckedIds[ItemId]);
				}
				MessageBox.Show(StringBuilderGhostReferences.ToString(), "Some references became used", MessageBoxButton.OK, MessageBoxImage.Information);
			}
		}
		public void Test()
		{
			DebugHelper.LogCall();
			if(IsShown)
			{
				UserControlWarningInstance.HideEx();
			}
			else
			{
				UserControlWarningInstance.ShowEx();
			}
			IsShown = !IsShown;
		}
		bool IsShown = true;

		#endregion

		#region Events' Handlers

		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1300:SpecifyMessageBoxOptions")]
		private void button1_Click(object sender, RoutedEventArgs e)
		{
			MessageBox.Show(string.Format(System.Globalization.CultureInfo.CurrentUICulture, "We are inside {0}.button1_Click()", this.ToString()), "Test Tool Window");
		}
		void CheckBoxTreeViewItem_Checked(object sender, RoutedEventArgs e)
		{
			CheckBoxTreeViewItem item = (CheckBoxTreeViewItem)sender;
			UpdateCheckStatus(item);
			CheckChildren(item);
			if(item.Parent != null && item.Parent is CheckBoxTreeViewItem)
			{
				CheckAlongParents((CheckBoxTreeViewItem)item.Parent, item.IsChecked);
			}
			if(ItemCheckedChanged != null)
			{
				ItemCheckedChanged(this, EventArgs.Empty);
			}
		}
		void item_ItemsChanged(CheckBoxTreeViewItem item, object sender, NotifyCollectionChangedEventArgs e)
		{
			if(e.Action != NotifyCollectionChangedAction.Move && e.Action != NotifyCollectionChangedAction.Replace)
			{
				CheckAlongParents(item);
			}
		}
		#endregion

		#region Helper Functions

		private void UpdateCheckStatus(CheckBoxTreeViewItem item)
		{
			if(((IVsHierarchyWrapper)item.Tag).IsReference)
			{
				NumberOfCheckedReferences += (item.IsChecked.Value) ? 1 : -1;
			}
		}
		private CheckBoxTreeViewItem CreateCheckBoxTreeViewItem(IVsHierarchyWrapper hier)
		{
			CheckBoxTreeViewItem item = new CheckBoxTreeViewItem(hier.Caption, false, hier.Bitmap, hier.OpenFolderBitmap);
			//item.Height = 18;
			item.Checked += new RoutedEventHandler(CheckBoxTreeViewItem_Checked);
			item.Indeterminate += new RoutedEventHandler(CheckBoxTreeViewItem_Checked);
			item.Unchecked += new RoutedEventHandler(CheckBoxTreeViewItem_Checked);
			item.ItemsChanged += new CheckBoxTreeViewItem.NotifyItemsChangedEventHandler(item_ItemsChanged);
			item.Tag = hier;
			item.ImagesStretch = System.Windows.Media.Stretch.None;
			item.PreferedHeight = 18;
			return item;
		}
		private bool ChecIfkReferenceIsUsed(IVsHierarchyWrapper IVsH)
		{
			List<AssemblyName> ProjectUsedReferencedAssemblies = (List<AssemblyName>)HashtableProjectUsedReferencedAssemblis[IVsH.Parent.Parent.ToProject().FullName];
			return ProjectUsedReferencedAssemblies.ContainsEx(IVsH);
		}
		private bool CheckAddingNode(IVsHierarchyWrapper IVsH)
		{
			return (IVsH.IsReferencesFolder || (IVsH.IsReference && !ChecIfkReferenceIsUsed(IVsH)) || (IVsH.IsProject && HashtableProjectUsedReferencedAssemblis.Contains(IVsH.ToProject().FullName)));
		}
		private void CheckChildren(CheckBoxTreeViewItem Parent)
		{
			Parent.BeginUpdate();
			if(!Parent.IsChecked.HasValue)
			{
				Parent.IsChecked = false;
			}
			foreach(CheckBoxTreeViewItem child in Parent.Items)
			{
				child.BeginUpdate();
				child.IsChecked = Parent.IsChecked;
				UpdateCheckStatus(child);
				CheckChildren(child);
				child.EndUpdate();
			}
			Parent.EndUpdate();
		}
		private void CheckParents(CheckBoxTreeViewItem item)
		{
			if(item.IsBeingUpdated || item.Parent == null || !(item.Parent is CheckBoxTreeViewItem))
			{
				return;
			}
			((CheckBoxTreeViewItem)item.Parent).BeginUpdate();
			bool? AnyState = ((CheckBoxTreeViewItem)((CheckBoxTreeViewItem)item.Parent).Items[0]).IsChecked;
			bool? NewState = false;
			foreach(CheckBoxTreeViewItem itemBrother in ((CheckBoxTreeViewItem)item.Parent).Items)
			{
				if(!AnyState.HasValue || itemBrother.IsChecked != AnyState)
				{
					NewState = null;
					break;
				}
				else
				{
					AnyState = itemBrother.IsChecked;
					NewState = AnyState;
				}
			}
			((CheckBoxTreeViewItem)item.Parent).IsChecked = NewState;
			((CheckBoxTreeViewItem)item.Parent).EndUpdate();
			CheckParents((CheckBoxTreeViewItem)item.Parent);
		}
		private void CheckAlongParents(CheckBoxTreeViewItem item)
		{
			if(item.Items.Count == 0)
			{
				CheckAlongParents(item, false);
			}
			else
			{
				CheckAlongParents(item, ((CheckBoxTreeViewItem)item.Items[0]).IsChecked);
			}
		}
		private void CheckAlongParents(CheckBoxTreeViewItem Item, bool? StateOfAnyChildOfItem)
		{
			if(Item == null || Item.IsBeingUpdated)
			{
				return;
			}
			Item.BeginUpdate();
			bool? NewState = StateOfAnyChildOfItem;
			if(StateOfAnyChildOfItem.HasValue)
			{
				foreach(CheckBoxTreeViewItem itemBrother in Item.Items)
				{
					if(itemBrother.IsChecked != StateOfAnyChildOfItem)
					{
						NewState = null;
						break;
					}
				}
			}
			else
			{
				NewState = null;
			}
			Item.IsChecked = NewState;
			Item.EndUpdate();
			if(Item.Parent != null && Item.Parent is CheckBoxTreeViewItem)
			{
				CheckAlongParents((CheckBoxTreeViewItem)Item.Parent, Item.IsChecked);
			}
		}
		private void GetNodesXML(string OutputPath)
		{
			string stringImagesFolderFullPath = System.IO.Path.Combine(OutputPath, stringImagePath);
			foreach(CheckBoxTreeViewItem Item in TreeViewSolutionHierarchy.Items)
			{
				DumpCheckBoxTreeViewItem(Item, stringImagesFolderFullPath);
			}
		}
		private void DumpCheckBoxTreeViewItem(CheckBoxTreeViewItem Item, string ImagesFolderFullPath)
		{
			Item.CollapsedStateImageEx.Save(string.Format("{0}\\{1}_C.png", ImagesFolderFullPath, StringBuilderNodesXml.Length + 1));
			Item.ExpandedStateImageEx.Save(string.Format("{0}\\{1}_E.png", ImagesFolderFullPath, StringBuilderNodesXml.Length + 1));
			StringBuilderNodesXml.AppendFormat(@"<item id=""{0}"" text=""{1}""{2} open=""1"" im0=""{0}_C.png"" im1=""{0}_E.png"" im2=""{0}_C.png"">", StringBuilderNodesXml.Length + 1, Item.Text, ((Item.IsChecked.HasValue && Item.IsChecked.Value) ? " checked=\"1\"" : ""), "");
			foreach(CheckBoxTreeViewItem ChildItem in Item.Items)
			{
				DumpCheckBoxTreeViewItem(ChildItem, ImagesFolderFullPath);
			}
			StringBuilderNodesXml.Append("</item>");
		}
		private string ExportHtmlContent(string OutputPath, string Title)
		{
			DebugHelper.LogCall();
			string stringOutputDirectory = System.IO.Path.Combine(OutputPath, Title);
			string stringDefaultFileResourceName = string.Empty;
			string FileFullPath = null;
			if(!System.IO.Directory.Exists(stringOutputDirectory))
			{
				System.IO.Directory.CreateDirectory(stringOutputDirectory);
			}
			foreach(string stringManifestResourceName in Assembly.GetExecutingAssembly().GetManifestResourceNames())
			{
				if(stringManifestResourceName.Contains(stringReportFolder))
				{
					if(stringDefaultFileResourceName.Length == 0 && stringManifestResourceName.EndsWith("Default.html"))
					{
						stringDefaultFileResourceName = stringManifestResourceName;
						continue;
					}
					FileFullPath = GetSuitableOutputPath(stringManifestResourceName, stringOutputDirectory);
					ExportResource(stringManifestResourceName, FileFullPath);
				}
			}
			return stringDefaultFileResourceName;
		}
		private string GetSuitableOutputPath(string SourceResourceName, string OutputDirectory)
		{
			DebugHelper.LogCall();
			StringBuilder stringFileName = new StringBuilder(SourceResourceName.Substring(SourceResourceName.IndexOf(stringReportFolder) + stringReportFolder.Length));
			stringFileName.Replace(".", "\\");
			stringFileName.Replace("\\", ".", stringFileName.ToString().LastIndexOf("\\"), 1);
			return System.IO.Path.Combine(OutputDirectory, stringFileName.ToString());
		}
		private void ExportResource(string SourceResourceName, string TargetFilePath)
		{
			DebugHelper.LogCall();
			System.IO.Stream ss = Assembly.GetExecutingAssembly().GetManifestResourceStream(SourceResourceName);
			System.IO.BinaryReader StreamReaderForResource = new System.IO.BinaryReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(SourceResourceName));
			string DirectoryFullPath = System.IO.Path.GetDirectoryName(TargetFilePath);
			if(!System.IO.Directory.Exists(DirectoryFullPath))
			{
				System.IO.Directory.CreateDirectory(DirectoryFullPath);
			}
			System.IO.File.WriteAllBytes(TargetFilePath, StreamReaderForResource.ReadBytes((int)ss.Length));
			StreamReaderForResource.Close();
		}
		private void ExportResource(string SourceResourceName, string TargetFilePath, params object[] Replacements)
		{
			DebugHelper.LogCall();
			System.IO.StreamReader StreamReaderForResource = new System.IO.StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(SourceResourceName));
			string DirectoryFullPath = System.IO.Path.GetDirectoryName(TargetFilePath);
			if(!System.IO.Directory.Exists(DirectoryFullPath))
			{
				System.IO.Directory.CreateDirectory(DirectoryFullPath);
			}
			System.IO.File.WriteAllText(TargetFilePath, string.Format(StreamReaderForResource.ReadToEnd(), Replacements));
			StreamReaderForResource.Close();
		}
		private void GetHChildren(CheckBoxTreeViewItem Target, IVsHierarchyWrapper Source)
		{
			foreach(IVsHierarchyWrapper pi in Source.Children)
			{
				if(!CheckAddingNode(pi))
				{
					continue;
				}
				CheckBoxTreeViewItem TN = CreateCheckBoxTreeViewItem(pi);
				Target.Items.Add(TN);
				GetHChildren(TN, pi);
			}
		}
		private string GetProjectsMarkup()
		{
			DebugHelper.LogCall();
			StringBuilder StringBuilderProjects = new StringBuilder();
			foreach(CheckBoxTreeViewItem CheckBoxTreeViewItemProject in ((CheckBoxTreeViewItem)TreeViewSolutionHierarchy.Items[0]).Items)
			{
				EnvDTE.Project ProjectInstance = ((IVsHierarchyWrapper)CheckBoxTreeViewItemProject.Tag).ToProject();
				StringBuilderProjects.AppendFormat(stringProjectMarkup, CheckBoxTreeViewItemProject.Text, ProjectInstance.FullName, ((CheckBoxTreeViewItem)CheckBoxTreeViewItemProject.Items[0]).Items.Count, GetReferencesMarkup(CheckBoxTreeViewItemProject));
			}
			return StringBuilderProjects.ToString();
		}
		private string GetReferencesMarkup(CheckBoxTreeViewItem CheckBoxTreeViewItemProject)
		{
			DebugHelper.LogCall();
			StringBuilder StringBuilderReferences = new StringBuilder();
			foreach(CheckBoxTreeViewItem CheckBoxTreeViewItemReference in ((CheckBoxTreeViewItem)CheckBoxTreeViewItemProject.Items[0]).Items)
			{
				IVsHierarchyWrapper IVsHierarchyWrapperReference = (IVsHierarchyWrapper)CheckBoxTreeViewItemReference.Tag;
				Reference ReferenceInternal = IVsHierarchyWrapperReference.ToReference();
				StringBuilderReferences.AppendFormat(stringReferenceMarkup, CheckBoxTreeViewItemReference.Text, ((ReferenceInternal == null) ? "Assembly" : ReferenceInternal.GetTypeName()), ((ReferenceInternal != null && ReferenceInternal.SourceProject != null) ? "Yes" : "No"), IVsHierarchyWrapperReference.FilePath);
				intNumberOfUnusedReferencesInSolution += 1;
			}
			return StringBuilderReferences.ToString();
		}
		private string GetSettingsMarkup(Hashtable HashtableScanningSettingsForDisplay)
		{
			DebugHelper.LogCall();
			StringBuilder StringBuilderSettings = new StringBuilder();
			StringBuilderSettings.Append(GetSettingsMarkup(SettingsCategory.Scanning, HashtableScanningSettingsForDisplay));
			StringBuilderSettings.Append(GetSettingsMarkup(SettingsCategory.Reporting, Options.GetSettingsForDisplay(SettingsCategory.Reporting)));
			return StringBuilderSettings.ToString();
		}
		private string GetSettingsMarkup(SettingsCategory Category, Hashtable SettingsForDisplay)
		{
			DebugHelper.LogCall();
			StringBuilder StringBuilderSettings = new StringBuilder();
			StringBuilderSettings.AppendFormat(stringSettingsMarkup, Category.ToString(), GetSettingMarkup(SettingsForDisplay));
			return StringBuilderSettings.ToString();
		}
		private string GetSettingMarkup(Hashtable SettingsForDisplay)
		{
			DebugHelper.LogCall();
			StringBuilder StringBuilderSetting = new StringBuilder();
			foreach(DictionaryEntry Entry in SettingsForDisplay)
			{
				StringBuilderSetting.AppendFormat(stringSettingMarkup, Entry.Key, Entry.Value);
			}
			return StringBuilderSetting.ToString();
		}

		#endregion

		#region Properties
		
		public int NumberOfCheckedReferences
		{
			get;
			private set;
		}
		public int NumberOfNodes
		{
			get
			{
				return TreeViewSolutionHierarchy.Items.Count;
			}
		}
		internal DialogPageOptionsGeneral Options
		{
			get;
			set;
		}

		#endregion
	}
}